package com.yy.hi.library.hilog;

import android.util.Log;

import org.jetbrains.annotations.NotNull;

import static com.yy.hi.library.hilog.HiLogConfig.MAX_LEN;

/**
 * User: gongyongfeng2@yy.com
 * Date: 2020/6/11 12 :55
 */
public class HiConsolePrinter implements HiLogPrint {
    @Override
    public void print(@NotNull HiLogConfig config, int level, String tag,
                      @NotNull String printString) {
        int len = printString.length();
        int countOfSub = len / MAX_LEN;
        if (countOfSub > 0) {
            int index = 0;
            for (int i = 0; i < countOfSub; i++) {
                Log.println(level, tag, printString.substring(index, index + MAX_LEN));
                index += MAX_LEN;
            }

            if (index != len) {
                Log.println(level, tag, printString.substring(index, len));
            }
        } else {
            Log.println(level, tag, printString);
        }
    }
}
